#include <vector>
#include <iostream>
using namespace std;

int theLostCow(int x /*John*/, int y /*Bessie*/) {
  vector<int> positions; // John 每一次停留下来的位置

  if (x < y) {
    int distance = 1;

    // 只要 John 停留下来的位置在 Bessie 的左边
    // John 就要来回来去走
    while (x + distance < y) {
      positions.push_back(x + distance);
      distance *= -2;
    }

    // John 就站在 Bessie 的右边了
    positions.push_back(x + distance);
    // poisitions
    // [4,    1,    7]
    // 
    int ans = 1;

    for (int i = 0; i < positions.size() - 1; ++i) {
      ans += abs(positions[i] - positions[i + 1]);
    }

    ans -= positions.back() - y;

    return ans;
  }
  else if (x > y) /*John is on the right*/ {
    //
    return 0;
  }
  else { // John is at the position of Bessie.
    return 0;
  }
}


int main(int argc, char const *argv[])
{
  /* code */
  // cd ..
  int x = 3, y = 6;
  cout << theLostCow(3, 6) << endl;
  return 0;
}
